<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  
</head>
<body>
  <div id="app">
    {{ num }}
    {{ doubleNum }}
    <button @click="change">改变计算属性 </button>
  </div>
  <script src="./vue.js"></script>
  <script>
    const vm = new Vue({
      el: '#app',
      data:{
        num: 2
      },
      methods: {
        change(){
          this.doubleNum = 100;
        }
      },
      computed: {
        doubleNum: {
          get(){
            return this.num*2
          },
          set(val){ // 拦截计算属性的 设置操作
            console.log(val,'setter触发');
            // 在setter中去修改依赖
            this.num = val/2;
          }
        }
      }
    })
  </script>
</body>
</html>